/**
 * 
 */
package org.ranch.web;

import org.ranch.model.Animal;

/**
 * This class is used to extract different commponets of data sent from the
 * mobile application.
 * 
 * @author Jonathan
 * 
 */

public class MidletParserUtils {
    
    public MidletParserUtils(){}

    /**
     * data == admin|admin123> where admin >> username admin123 >> password
     * 
     * @param data
     * @return
     */
    public String getUsername(String data) {
	return data.substring(0, data.indexOf("|"));
    }

    public String getPassword(String data) {
	return data.substring(data.indexOf("|") + 1, data.length());
    }

    public String getUserCredentials(String data) {
	int index = data.indexOf("*");
	return data.substring(0, index);
    }

    public Animal getAnimal(String data) {
	String d = data.substring(data.indexOf("*"), data.length());
	if(d.length() > 1){
	    Animal animal = new Animal();
	    animal.setEarTag("099");
	    return animal;
	}
	return null;
    }
}
